package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/product/baseTrademark")
public class BaseTrademarkController {

    @Autowired
    BaseTrademarkService baseTrademarkService;

    // /admin/product/baseTrademark/{page}/{limit}
    @GetMapping("{page}/{limit}")
    public Result baseTrademarkList(@PathVariable Long page,
                                    @PathVariable Long limit){

        Page pageModel = new Page(page,limit);
        IPage<BaseTrademark> baseTrademarkIPage = this.baseTrademarkService.
                getbaseTrademarkList(pageModel);
        return Result.ok(baseTrademarkIPage);
    }
    // /admin/product/baseTrademark/remove/{id}
    @DeleteMapping("remove/{id}")
    public Result baseTrademarkRemove(@PathVariable Long id){

       //baseTrademarkService.deleteById(id);
        this.baseTrademarkService.deleteById(id);
        return Result.ok();
    }
    // /admin/product/baseTrademark/save
    @PostMapping("save")
    public Result baseTrademarkSave(@RequestBody BaseTrademark baseTrademark){
        //调用服务层
        this.baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }
    // /admin/product/baseTrademark/get/{id}
    @GetMapping("get/{id}")
    public Result baseTrademarkById(@PathVariable Long id){
        BaseTrademark baseTrademark = this.baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }
    // /admin/product/baseTrademark/update
    @PutMapping("update")
    public Result baseTrademarkUpdate(@RequestBody BaseTrademark baseTrademark){
        this.baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }
}
